package com.xxxx.server.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xxxx.server.mapper.EmployeeMapper;

import com.xxxx.server.page.EmployeePage;
import com.xxxx.server.pojo.Employee;

import com.xxxx.server.service.IEmployeeService;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Service;


import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zhoubin
 * @since 2020-08-17
 */
@Service
public class EmployeeServiceImpl extends ServiceImpl<EmployeeMapper, Employee> implements IEmployeeService {

    @Autowired
    private  EmployeeMapper employeeMapper;

    @Override
    public Object findList(IPage<Employee> page) {
        QueryWrapper<Employee> wrapper = new QueryWrapper<>();
        IPage<Employee> employeeIPage = baseMapper.selectPage(page, wrapper);
        return employeeIPage;
    }


    /**
     * 多条件查询员工对象
     * @param basePage
     * @return
     */
    @Override
    public Map<String, Object> queryByParamsForTable(EmployeePage basePage) {
        Map<String,Object> result = new HashMap<String,Object>();
        PageHelper.startPage(basePage.getPage(),basePage.getLimit());
        PageInfo<Employee> pageInfo =new PageInfo<Employee>(employeeMapper.selectByParams(basePage));
        result.put("count",pageInfo.getTotal());
        result.put("data",pageInfo.getList());
        result.put("code",0);
        result.put("msg","");
        return result;
    }


    /**
     * 根据员工姓名查询员工对象
        如果：
             1. 员工姓名为空
             2. 员工姓名和数据库中查询比较，员工姓名不存在
        否则：成功
            获取数据库中的数据
     * @param name
     * @return
     */
    @Override
    public Employee getEmployeeByName(String name) {
        if (name == null || name == ""){
            System.out.println("员工姓名不能为空！！！");
        }
        return employeeMapper.selectOne(new QueryWrapper<Employee>().eq("name",name));
    }

    /**
     * 添加员工信息
        进行校验：
            数据不能为空
     * @param employee
     * @return
     */
    @Override
    public Employee saveEmployee(Employee employee) {
        return null;
    }


    //导出数据
    @Override
    public List<Employee> findAllEmployee() {
        return employeeMapper.findAllEmployee();
    }




}
